﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Collections;
using GPCSC.Web;
using NickLee.Common;
using System.Text;
using Maticsoft.Common;

namespace GPCSC.Web.sjs
{
    public partial class lihz : PageBase
    {

        public StringBuilder xjc = new StringBuilder();//统计历史
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
               
                load();

            }
        }
        protected void load()
        {
            DataSet ds = new DataSet();
            byte[] userInfo = (byte[])base.o_baseTable[c_obj.s_userInfo];
            Hashtable userInfoTable = CompressData.UnCompressHashtable(userInfo);
            Model.CL_USER_S users = (Model.CL_USER_S)userInfoTable["SYS_USER"];
            Hashtable htable = new Hashtable();

            htable.Add("@postid", users.CL_POSTID_PK.ToString());
            ds = new SqlReadXml().ReaderDataSet("sel_tjls_all", htable);
            if (ds.Tables.Count > 0)
            {

                if (ds.Tables[0].Rows.Count > 0)
                {
                    xjc.Append("<table>");
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                      
                        int mods = i % 3;
                        switch (mods)
                        {

                            case 0:
                                xjc.Append("<tr>");
                                xjc.Append("<td ><img src=\"image/lb.jpg\"  /><br /><input type='radio' name='ra' onclick=\"opne('" + ds.Tables[0].Rows[i]["FileID"].ToString() + "')\">" + ds.Tables[0].Rows[i]["filename"].ToString() + "<br />" + ds.Tables[0].Rows[i]["TJdate"].ToString() + "</td>");
                                break;
                            case 1:
                                xjc.Append("<td ><img src=\"image/lb.jpg\" /><br /><input type='radio' name='ra' onclick=\"opne('" + ds.Tables[0].Rows[i]["FileID"].ToString() + "')\">" + ds.Tables[0].Rows[i]["filename"].ToString() + "<br />" + ds.Tables[0].Rows[i]["TJdate"].ToString() + "</td>");
                                break;
                            case 2:
                                xjc.Append("<td ><img src=\"image/lb.jpg\"  /><br /><input type='radio' name='ra' onclick=\"opne('" + ds.Tables[0].Rows[i]["FileID"].ToString() + "')\">" + ds.Tables[0].Rows[i]["filename"].ToString() + "<br />" + ds.Tables[0].Rows[i]["TJdate"].ToString() + "</td>");
                                xjc.Append("</tr>");
                                break;
                        }
                    }
                    int len = ds.Tables[0].Rows.Count;
                    if (len % 3 != 0)
                    {
                        xjc.Append("</tr>");
                    }
                    xjc.Append("</table>");
                }
            }

        }
        public  object reword()
        {
            //panl.InnerHtml = "<div>测试</div>";

            ////Panel1.RenderControl(textWriter);
            //Response.Clear();
            //System.Globalization.CultureInfo cultureInfo = new System.Globalization.CultureInfo("ZH-CN", true);
            //System.IO.StringWriter stringWriter = new System.IO.StringWriter(cultureInfo);
            ////stringWriter.Write("<div>ceshi</div>");
            //Response.BufferOutput = true;
            ////设定输出的字符集
            //Response.Charset = "GB2312";
            ////假定导出的文件名为FileName.doc
            //Response.AppendHeader("Content-Disposition", "attachment;filename= 三进三帮统计表.doc");
            //Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
            ///**/
            //////设置导出文件的格式
            //Response.ContentType = "application/ms-word";

            //System.Web.UI.HtmlTextWriter textWriter = new System.Web.UI.HtmlTextWriter(stringWriter);
            //panl.RenderControl(textWriter);


            //Response.Write(stringWriter.ToString());
            //Response.End();
            return null;

        }

        /// <summary>
        /// 下载
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Button1_Click(object sender, EventArgs e)
        {
            string ids = this.ids.Value;
            if (ids == string.Empty)
            {
                MessageBox.Show(this, "没有数据");

                return;
            }

          string filename=  geifile(ids);
           
              Response.Clear();
              System.Globalization.CultureInfo cultureInfo = new System.Globalization.CultureInfo("ZH-CN", true);
              System.IO.StringWriter stringWriter = new System.IO.StringWriter(cultureInfo);
              //stringWriter.Write("<div>ceshi</div>");
              Response.BufferOutput = true;
              //设定输出的字符集
              //Response.Charset = "GB2312";
              //假定导出的文件名为FileName.doc
              Response.AppendHeader("Content-Disposition", "attachment;filename=" + Server.UrlEncode(filename));
              //  Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
              /**/
              ////设置导出文件的格式
              Response.ContentType = "application/ms-word";

              System.Web.UI.HtmlTextWriter textWriter = new System.Web.UI.HtmlTextWriter(stringWriter);
              panl.RenderControl(textWriter);


              Response.Write(stringWriter.ToString());
              Response.End();
           

        }

        protected string  geifile( string id)
        {
            Hashtable htable = new Hashtable();
            htable.Add("@FileID", id);
            DataSet ds = new SqlReadXml().ReaderDataSet("tifilebyiod", htable);
            panl.InnerHtml = ds.Tables[0].Rows[0]["fileUrl"].ToString();
             
                return ds.Tables[0].Rows[0]["filename"].ToString();
             
        }


       
    }
}